package com.foyekoo.project001.model;

import android.databinding.ObservableField;
import android.os.Parcelable;
import android.widget.CompoundButton;
import android.widget.SeekBar;

import com.foyekoo.project001.App;
import com.foyekoo.project001.command.Command;
import com.foyekoo.project001.config.LocalClient;
import com.foyekoo.project001.config.SpUtil;
import com.foyekoo.project001.utils.ToastUtils;

public class ClientBaseSetVM extends BaseVM {

    public ObservableField<Boolean> waitingStatus = new ObservableField<>(true);
    public ObservableField<Boolean> bgmStatus = new ObservableField<>(true);

    /**
     * 开始键 是否按下 如果是 true 不是 false   通过改变这个true 和false 来控制页面的显示
     */
    public ObservableField<Boolean> startKeyIsClick = new ObservableField<>();

    /**
     * 向右键是否按下
     */
    public ObservableField<Boolean> toRightKeyIsClick = new ObservableField<>();

    /**
     * 微动下
     */
    public ObservableField<Boolean> frettingDownKeyIsClick = new ObservableField<>();

    /**
     * 微动左
     */
    public ObservableField<Boolean> frettingleftKeyIsClick = new ObservableField<>();

    /**
     * 微动右
     */
    public ObservableField<Boolean> frettingRightKeyIsClick = new ObservableField<>();

    /**
     * 菜单键
     */
    public ObservableField<Boolean> menuKeyIsClick = new ObservableField<>();

    /**
     * 5局1 键
     */
    public ObservableField<Boolean> fiveGameKeyIsClick = new ObservableField<>();

    /**
     * 投币键
     */
    public ObservableField<Boolean> inCoinKeyIsClick = new ObservableField<>();

    /**
     * 确认键
     */
    public ObservableField<Boolean> confirmKeyIsClick = new ObservableField<>();

    /**
     * 上键
     */
    public ObservableField<Boolean> upKeyIsClick = new ObservableField<>();

    /**
     *下键
     */
    public ObservableField<Boolean> downKeyIsClick = new ObservableField<>();

    /**
     * 左键
     */
    public ObservableField<Boolean> leftKeyIsClick = new ObservableField<>();

    /**
     * 右键
     */
    public ObservableField<Boolean> rightKeyIsClick = new ObservableField<>();


    /**
     * 落物光眼
     */
    public ObservableField<Boolean> dropProductEyes = new ObservableField<>();


    /**
     * 左右电机位置
     */
    public ObservableField<String> leftRightMachineryPosition = new ObservableField<>();

    /**
     * 前后电机位置
     */
    public ObservableField<String> frontBehindMachineryPosition = new ObservableField<>();


    /**
     * 上下电机位置
     */
    public ObservableField<String> upDownMachineryPosition = new ObservableField<>();


    public ObservableField<String> timeAutoSet = new ObservableField<>();

    /**
     * 掉电保存状态
     */
    public ObservableField<Boolean> saveStatues = new ObservableField<>(true);

    /**
     * 老化测试文字
     */
    public ObservableField<String>  oldControlText = new ObservableField<>("关闭中");

    /**
     * 音乐播放间隔
     */
    public ObservableField<Integer> musicInterval = new ObservableField<>(10);
    /**
     *
     */
    public ObservableField<String> musicIntervalText = new ObservableField<>();

    /**
     * 时间矫正
     */
    public ObservableField<Integer> autoTime = new ObservableField<>();

    /**
     * 时间矫正
     */
    public ObservableField<String> autoTimeText = new ObservableField<>();

    /**
     * 最高点测试
     */
    public ObservableField<String> yMax = new ObservableField<>();

    /**
     * 投币测试数量
     */
    public ObservableField<String> coinTestNum = new ObservableField<>();

    public ClientBaseSetVM(){
        LocalClient client = SpUtil.getInstance().getLocalClient();
        saveStatues.set(client.saveStatus == 1 ? true :false);
        waitingStatus.set(client.waitingMusicIsOpen);
        bgmStatus.set(client.backGroundMusicIsOpen);
        autoTimeText.set(client.autoCheckTime + "");
        autoTime.set(client.autoCheckTime);
        musicInterval.set(client.waitingMusicInterval);
        musicIntervalText.set(client.waitingMusicInterval + "");

        timeAutoSet.set("100");

    }

    public void musicAdd(){
        int progress = musicInterval.get();
        progress = progress +1;
        musicInterval.set(progress);
        musicIntervalText.set(progress +"");
        LocalClient c = SpUtil.getInstance().getLocalClient();
        c.waitingMusicInterval = progress;
        SpUtil.getInstance().saveCurrentClient(c);
    }

    public void musicReduce(){

        int progress = musicInterval.get();
        if (progress == 0) return;
        progress = progress -1;
        musicInterval.set(progress);
        musicIntervalText.set(progress +"");
        LocalClient c = SpUtil.getInstance().getLocalClient();
        c.waitingMusicInterval = progress;
        SpUtil.getInstance().saveCurrentClient(c);
    }

    public void musicIntervalChange(SeekBar seekBar, int progress, boolean fromUser) {
        musicInterval.set(progress);
        musicIntervalText.set(progress + "");
        LocalClient c = SpUtil.getInstance().getLocalClient();
        c.waitingMusicInterval = progress;
        SpUtil.getInstance().saveCurrentClient(c);
    }

    public void autoTimeChange(SeekBar seekBar, int progress, boolean fromUser) {
        autoTime.set(progress);
        autoTimeText.set(progress + "");
        LocalClient c = SpUtil.getInstance().getLocalClient();
        c.autoCheckTime = progress;
        SpUtil.getInstance().saveCurrentClient(c);
    }

    public void autoTimeAddClick(){
        int progress = autoTime.get();
        progress = progress +1;
        autoTime.set(progress);
        autoTimeText.set(progress +"");
        LocalClient c = SpUtil.getInstance().getLocalClient();
        c.autoCheckTime = progress;
        SpUtil.getInstance().saveCurrentClient(c);

    }

    public void autoTimeReduceClick(){
        int progress = autoTime.get();
        if (progress == 0) return ;
        progress = progress -1;
        autoTime.set(progress);
        autoTimeText.set(progress +"");
        LocalClient c = SpUtil.getInstance().getLocalClient();
        c.autoCheckTime = progress;
        SpUtil.getInstance().saveCurrentClient(c);
    }




    public void bgMusicSetting(CompoundButton compoundButton , boolean isCheck){
        LocalClient client = SpUtil.getInstance().getLocalClient();
        client.backGroundMusicIsOpen = isCheck;
        SpUtil.getInstance().saveCurrentClient(client);
    }

    public void waitMusicSetting(CompoundButton compoundButton , boolean isCheck){
        LocalClient client = SpUtil.getInstance().getLocalClient();
        client.waitingMusicIsOpen = isCheck;
        SpUtil.getInstance().saveCurrentClient(client);
    }



    /**
     * 左电机 最高值
     */
    public void upHeightMachinery(){
        Command.machineryMaxHeight();
    }

    /**
     * 右电机最高值
     */
    public void  downHeightMachinery(){
        Command.machineryMaxHeight();
    }


    public void oldTestControl(CompoundButton view, boolean isCheck){
        if (isCheck) {
            oldControlText.set("正在老化测试..");
        } else {
            oldControlText.set("已关闭");
        }
        Command.oldTestControl(isCheck);
    }

    /**
     * 掉电保存
     * @param view
     * @param isCheck
     */
    public void saveStatusControl(CompoundButton view,boolean isCheck){
        Command.updateSaveStatus(isCheck);
    }

    /**
     * 灯光控制
     * @param view
     * @param isCheck
     */
    public void lightControl(CompoundButton view , boolean isCheck){
        ToastUtils.show(App.getInstance(),"light control");
        Command.lightControl(isCheck);

    }

    /**
     * 电机测试右
     */
    public void rightMachinery(int cmd){
        Command.machineryTest(1,cmd);
    }

    /**
     * 电机测试上
     */
    public void upMachinery(int cmd){
        Command.machineryTest(2,cmd);
    }

    /**
     * 电机测试左
     */
    public void leftMachinery(int cmd){
        Command.machineryTest(1,cmd);

    }


    /**
     * 电机测试下
     */
    public void downMachinery(int cmd){
        Command.machineryTest(2,cmd);
    }
    /**
     * 电机测试前
     */
    public void frontMachinery(int cmd){
        Command.machineryTest(0,cmd);
    }


    /**
     * 电机测试后
     */
    public void behindMachinery(int cmd){
        Command.machineryTest(0,cmd);
    }
}
